package leetcode.二叉树;

public class 根据二叉树创建字符串606 {

    public String tree2str(TreeNode root) {
        if(root == null) return "";
        StringBuilder ans = new StringBuilder();
        ans.append(root.val);
        if(root.right != null || root.left!= null)
            ans.append("(" + tree2str(root.left) + ")");
        if(root.right != null)
            ans .append("(" + tree2str(root.right) + ")");
        return ans.toString();

    }

}
